import { fetch } from '@/utils/request'
import type { UserLoginModel, UserModel } from './models/userModel'
import type { PageModel } from './models/baseModel'

const Api = {
  Login: `/public/user/sign/in`,
  List: `/user/list`,
  Add: `/user`,
  DeleteById: (id: number) => `/user/${id}`,
  UpdateById: (id: number) => `/user/${id}`
}

export function postLogin<T>(data: UserLoginModel) {
  return fetch.post<T>(Api.Login, { data })
}

export function getList<T>(params: PageModel) {
  return fetch.get<T>(Api.List, { params })
}

export function deleteById<T>(id: number) {
  return fetch.delete<T>(Api.DeleteById(id))
}

export function putById<T>(data: UserModel) {
  return fetch.put<T>(Api.UpdateById(data.id), { data })
}

export function postAdd<T>(data: UserModel) {
  return fetch.post<T>(Api.Add, { data })
}
